package com.hcj.testThread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author: HuangChangjin 2017-12-03 16:55
 * @Description:
 */
public class Station extends Thread {
    private static final Logger log = LoggerFactory.getLogger(Station.class);
    public Station(String name){
        //super("线程名字:"+name);
        super();
    }

    // 定义票数
    static int tick = 20;
    static String key = "key";

    @Override
    public void run() {
        while (tick > 0){
            synchronized(key){
                if (tick > 0){
                    log.info("{}正在出售第{}张票", getName(),tick);
                    tick--;
                }else {
                    log.info("票买完了");
                }

            }
        }
        // 手动模拟 延时。。。
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        Station s1 = new Station("1号售票处");
        Station s2 = new Station("2号售票处");
        Station s3 = new Station("3号售票处");

        s1.start();
        s2.start();
        s3.start();
    }
}
